package com.springboot.demo.optional;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class OptionalTest {
    public static void main(String[] args) {
        Optional<User> user = Optional.of(new User());
        boolean present = user.isPresent();
//        Optional.ofNullable(new User()).
//                map(User::getAddress).
//                map(Address::getWait).
//                orElseThrow(()->{
//            System.out.println("errorrrrrrrrrrrrrrr");
//            return new RuntimeException();
//        });

      stream();
    }
    public static void stream(){
        List<List<Address>> list = new ArrayList<>();
        list.add(Arrays.asList(new Address("北京")));
        list.add(Arrays.asList(new Address("上海")));
        list.add(Arrays.asList(new Address("南京")));
        list.add(Arrays.asList(new Address("长沙")));
        list.add(Arrays.asList(new Address("广州")));
        list.stream().flatMap(u->u.stream()).map(Address::getWait).forEach(System.out::println);

        Optional<List<Address>> addresses = Optional.of(list).flatMap(l -> Optional.of(l.get(0)));
        System.out.println(addresses.get());
    }
}
